package com.xigege.netty.nettyComponent.byteBuf;

import com.xigege.netty.nettyComponent.byteBuf.util.DebugByteBufUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;

import java.nio.charset.Charset;

/**
 * @author huangxi
 * @class TestByteBuf
 * @description 创建ByteBuf
 * @create 2022-08-22 16:56
 */
public class TestByteBuf {
    public static void main(String[] args) {
        ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(300);
        DebugByteBufUtil.log(buf);
//        System.out.println(buf);
//        StringBuilder stringBuilder = new StringBuilder(300);
//        for (int i = 0; i < 300; i++) {
//            stringBuilder.append("a");
//        }
//        buf.writeBytes(stringBuilder.toString().getBytes(Charset.defaultCharset()));
        buf.writeInt(5);
        buf.writeInt(6);
        DebugByteBufUtil.log(buf);
        System.out.println(buf.readInt());
        DebugByteBufUtil.log(buf);
        // mark
        buf.markReaderIndex();
        System.out.println(buf.readInt());
        // reset
        buf.resetReaderIndex();
        DebugByteBufUtil.log(buf);
    }
}
